<?php
/**
 * Created by : PhpStorm
 * User: ZPF
 * Date: 2022/3/30
 * Time: 22:58
 */

namespace app\admin\controller;


use app\admin\model\RoleModel;
use app\BaseController;
use think\App;

class Role extends BaseController
{
    protected $middleware = [
        'CheckTokenMiddleware'
    ];

    /**
     * 角色列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function list()
    {

        $pageNo=request()->param('pageNo','1','int');
        $pageSize=request()->param('pageSize','10','int');
        $where=[];
        if($role_name=$this->request->param('role_name'))
            $where[]=['role_name','like',"%$role_name%"];
        $list=RoleModel::getList($where,$pageNo,$pageSize);
        $total=RoleModel::count($where);
        api_return(200,'success',['list'=>$list,'total'=>$total]);
    }
    /*角色编辑*/
    public function save(){
        if(request()->isPost()){
            $p = request()->post();
            $p['permission']=implode('-',$p['permission']);
            $res = RoleModel::editRole($p);
            api_return($res['code'],$res['msg']);
        }
        api_return(50001);

    }
    /*角色删除*/
    public function del()
    {
        $p=request()->post();
        $res=(RoleModel::del($p['ids']));
        api_return($res['code'],$res['msg']);
    }
}
